using System;
using System.Collections.Generic;
using System.Text;
using ITAP.Core.Modelling.Primitives;

namespace ITAP.ShprossesBuilder.Modelling.Components
{
    public class PrimitiveEnumerator : IEnumerator<IPrimitive>
    {
        IComponent owner;
        List<IPrimitive> allPrimitives;
        IPrimitive current;
        int currentIndex;

        public PrimitiveEnumerator(IComponent owner)
        {
            this.owner = owner;
            this.allPrimitives = new List<IPrimitive>();
            for (int i = 0; i < this.owner.Primitives.Count; i++)
            {
                this.allPrimitives.Add(this.owner.Primitives[i]);
                this.allPrimitives.AddRange(this.owner.Primitives[i].AllInnerPrimitives);
            }
            currentIndex = 0;
        }

        #region IEnumerator<IPrimitive> Members

        public IPrimitive Current
        {
            get { return current; }
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            
        }

        #endregion

        #region IEnumerator Members

        object System.Collections.IEnumerator.Current
        {
            get { return this.current; }
        }

        public bool MoveNext()
        {
            this.currentIndex++;
            if (this.currentIndex == this.allPrimitives.Count) return false;

            this.current = this.allPrimitives[currentIndex];
            return true;
        }

        public void Reset()
        {
            this.currentIndex = 0;
        }

        #endregion
    }

}
